package org.zxp.thread.tools;

import java.util.concurrent.CyclicBarrier;

/**
 * @program: zxp-thread-test
 * @description: CyclicBarrier测试
 * @author: X-Pacific zhang
 * @create: 2019-05-24 21:26
 **/
public class CyclicBarrierTest {
    public static void main(String[] args){
        CyclicBarrier cyclicBarrier = new CyclicBarrier(3,() -> {
            System.out.println("哨音响");
        });
        for (int i = 0; i < 6; i++) {
            int j = i;
            new Thread(() -> {
                try {
                    Thread.sleep(1*1000);
                    System.out.println(Thread.currentThread().getName()+"准备就绪");
                    cyclicBarrier.await();
                } catch (Exception e) {
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread().getName()+"开始执行");
            }).start();
        }

    }
}
